<?php

class PdoNews extends PdoConnect {

    public function readAll() {
        try {
            $this->open();
            $sql = "SELECT * From `news` LIMIT 0, 5";
            $prep = $this->pdo->prepare($sql);

            $prep->execute();
            $prep->setFetchMode(PDO::FETCH_ASSOC);


            return $prep;
            $this->close();
        } catch (PDOException $e) {
            $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
            die($msg);
        }
    }
     public function readOne($IdNews) {
        try {
            $this->open();
            $sql = "SELECT * From `news` Where IdNews=$IdNews";
            $prep = $this->pdo->prepare($sql);

            $prep->execute();

            $news = new News();
            $ligne = $prep->fetch(PDO::FETCH_OBJ);
            $news->setTypeNews($ligne->TYPENEWS);
            $news->setDateNews($ligne->DATENEWS);
            $news->setContenuNews($ligne->CONTENUNEWS);
            $news->setTitreNews($ligne->TITRENEWS);
            $news->setIdAdmin($ligne->IDADMIN);
            return $news;
        } catch (PDOException $e) {
            $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
            die($msg);
        }
    }

}
